<{include file="Public/top.html" }>
	</head>
	<body>
		<div id="warpper">
            <div class="content">
                <div class="location">会员活动</div>
                <{include file="./nav.html" }>
                <div class="filedSet" style="padding-bottom: 0;">
                    <div class="search">
                        <form action="<{U('Events/index')}>" id="searchForm" method="get" class="ui-form reportForm">
                            <input name="m" type="hidden" value="<{$module}>">
                            <input name="c" type="hidden" value="<{$controller}>">
                            <input name="a" type="hidden" value="<{$action}>">
                            <input name="actype" type="hidden" value="<{$actype}>">

                            <input name="p" id="page" type="hidden" value="<{$page|default:1}>">
                            <input name="limit" id="limit" type="hidden" value="<{$limit|default:10}>">
                            <div class="ui-form-item inline-block">
                                <label class="ui-label">关键字</label>
                                <input type="text" value="<{$keywords}>" class="ui-text bg-text keyword" name="keywords" placeholder="活动名" style="width: 80px;" />
                            </div>

                            <div class="ui-form-item inline-block">
                                <button type="submit" class="ui-button" onclick="LayerShow();">搜索</button>
                            </div>
                        </form>
                    </div>
                </div>

                <!--表格内容-->
                <div class="mainGrid">
                    <table class="ui-table ui-body">
                        <thead>
                        <tr>
                            <th class="pct20">活动名</th>
                            <th class="pct15">显示开始时间</th>
                            <{if $action eq 'index' and ($actype eq 'ing' or $actype eq 'end')}>
                                <{if $originalPriceSwitch}>
                                    <th class="pct10">原价</th>
                                <{/if}>
                                <th class="pct10">名额</th>
                                <th class="pct10">报名人数</th>
                            <{if $action eq 'index' and $actype eq 'end'}>
                                <th class="pct10">放鸽子</th>
                            <{/if}>
                                <th class="pct10">人气</th>
                                <th class="pct10">评论数</th>

                                <th class="pct10">外链点击量</th>
                            <{else if $action eq 'index' and $actype eq 'wait'}>
                                <{if $userLevelSwitch}>
                                    <th class="pct10">用户等级</th>
                                <{/if}>
                                <{if $originalPriceSwitch}>
                                    <th class="pct10">原价</th>
                                <{/if}>
                                <{if $currentPriceSwitch}>
                                    <th class="pct10">现价</th>
                                <{/if}>
                                <th class="pct10">积分</th>
                            <{/if}>
                            <th class="pct20 last-col">操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <{foreach from=$list item=item}>
                        <tr id="id_<{$item.id}>">
                            <td class="title" data="<{$item['imgList']}>"><a href="<{$WEBSITE}>wap.php?m=Wap&c=Events&a=info&id=<{$item['id']}>" target="_blank"><{$item['title']}></a></td>
                            <td><{$item['beginShowTime']|date_format:"%Y-%m-%d <br/> %H:%M:%S"}></td>
                            <{if $action eq index and ($actype eq 'ing' or $actype eq 'end')}>
                                <{if $originalPriceSwitch}>
                                    <td><{$item['originalPrice']}></td>
                                <{/if}>
                                <td><{if $item['places'] == 0}>不限<{else}><{$item['places']}><{/if}></td>
                                <td><{$item['applyCount']}></td>
                            <{if $action eq 'index' and $actype eq 'end'}>
                                <td><{$item['applyUnjoinCount']}></td>
                            <{/if}>
                                <td><{$item['hot'] }>(调节：<a href="javascript:void(0)" onclick="changeAdjust(this)" data-id="<{$item.id}>" style="color: blue;text-decoration: underline"><{$item['hotAdjust']}></a>)</td>
                            <td><a style="color:#2077d1;" href="<{u('comment/index?objType='|cat:$smarty.const.OBJ_TYPE_ACTIVITY)|cat:'&objID='|cat:$item['id']}>"><{$item['commentNum']}></a></td>
                                <td><{$item.jumpTimes}></td>
                            <{else if $action eq index and $actype eq 'wait'}>
                                <{if $userLevelSwitch}>
                                    <td><{$getLevelKv[$item['userLevel']]}></td>
                                <{/if}>
                                <{if $originalPriceSwitch}>
                                    <td><{$item['originalPrice']}></td>
                                <{/if}>
                                <{if $currentPriceSwitch}>
                                    <td><{$item['price']}></td>
                                <{/if}>
                                <td><{$item['point']}></td>
                            <{/if}>
                            <td class="ta_l">
                                <div class="handler">
                                    <{if $action eq index and ($actype eq 'ing' or $actype eq 'end')}>
                                        <a href="<{U('Events/applyList')}>&id=<{$item.id}>" onclick="LayerShow();">报名列表</a>
                                        <a href="javascript:addApply('<{$item.id}>');">新增</a>
                                        <a href="javascript:uploadPhoto('<{$item.id}>');">上传图片</a>
                                    <{/if}>
                                    <{if $action eq index and $actype eq 'end'}>
                                        <a href="<{U('Events/applyList')}>&id=<{$item.id}>&status=2" onclick="LayerShow();">中奖</a>
                                    <{/if}>
                                        <a href="<{U('Events/add')}>&id=<{$item.id}>" onclick="LayerShow();">修改</a>
                                    <{if $action eq index and ($actype eq 'end' or $actype eq 'wait')}>
                                        <a href="javascript:del('<{$item.id}>');">删除</a>
                                    <{/if}>



                                </div>
                            </td>
                        </tr>
                        <{/foreach}>
                        </tbody>
                    </table>
                </div>
                <div class="pagination">
                    <!--描述：分页-->
                    <{include file="Public/page.html" }>
                </div>
            </div>
		</div>
        <{include file="Public/foot.html" }>
	</body>
</html>
<script>
    var delUri = "<{U('Events/del')}>";
    var uploadPhotoUri = "<{U('Events/uploadPhoto')}>";
    function del(id){
        if(!confirm('是否执行删除操作')){
            return false;
        }
        $.get(delUri+"&id="+id,function(result){
            if(result.status==0) {
                $('#id_'+id).remove();
            }else{
                layer.msg(result.msg);
            }
        },'json');
    }

    function changeAdjust(obj){
        var eid=obj.dataset['id'];
        var num=window.prompt("请输入调节人气数，最终显示人气为实际人气+调节人气",0);
        if(num === null){
            return;
        }
        num=parseInt(num);
        if (isNaN(num)){
            layer.msg("请输入正整数！");return;
        }
        $.getJSON("<{u('changeAdjust')}>"+"&eid="+eid+"&num="+num,function(data){
            if (data.status==0){
                obj.innerHTML=num;
                layer.msg("设置成功！");
            }else{
                layer.msg("设置失败，请重试！");
            }
        });

    }

    $(document).ready(
            $('.title').on('mouseover',function (e) {
                if(e.target.tagName!='TD'){
                    return;
                }
                layer.closeAll();
                var url=$(e.target).attr('data');
                var title = e.target.innerText;
                layer.tips("<h1 style='color: #000000;text-overflow:ellipsis;overflow: hidden;display: -webkit-box;-webkit-line-clamp: 1;-webkit-box-orient: vertical;min-height: 25px;'>"+title+'</h1><img src="'+url+'" style="width:280px;height:140px;">', e.target,
                        {
                            tips:[4,'#ffffff'],
                            area: ['300px', '180px'],
                            skin:'BoxShadow',
                            time:100000
                        });

            })
    );



    function addApply(eid){
        var uidstr=window.prompt("");
        var uid=parseInt(uidstr);
        if(isNaN(uid)){
            //alert("请输入数字编号")
            return;
        }
        $.getJSON("<{u('addApply')}>"+"&eid="+eid+"&uid="+uid,function(data){
                layer.msg(data.msg);
        });


    }



    function uploadPhoto(eid,uid){
        if(!uid){
            uid=0;
        }
        $.get(uploadPhotoUri+"&eid="+eid+"&uid="+uid,function(data){
            details = dialog({
                title: '详情',
                width: 500,
                content: data,
                onshow: function(){
                    //$("#details form")[0].reset();
                },
            });
            details.showModal();


            $('.epic').on('mouseover',function (e) {
                if(e.target.tagName!='IMG'){
                    return;
                }
                layer.closeAll();
                var url=$(e.target).attr('src');
                layer.tips('<img src="'+url+'" style="width:280px;height:auto;">', e.target,
                        {
                            tips:[4,'#ffffff'],
                            area: ['300px', '180px'],
                            skin:'BoxShadow',
                            time:3000
                        });

            })


            $('#uploadEventPhoto').uploader();

        },'html')

    }


    (function ($) {
        'use strict';
        $.fn.uploader = function () {
            return this.each(function () {
                var $this = $(this);
                var $file = $this.find('input[type=file]');
                $file.AjaxFileUpload({
                    action: './api.php?m=Api&c=index&a=ajaxUploadArr&from=IMG_EVENT_OVER',
                    onSubmit: function () {
                    },
                    onComplete: function (filename, response) {
                        if(response.status==0 ){
                            var $p=$('#uploadEventPhoto');
                            for(var i=0;i<response.data.length;i++){
                                if(response.data[i].id>0) {
                                    $p.before("<span class='picture_box picture_80' >" +
                                            '<div class="a-imgBox" style="display:block;">' +
                                            '<a href="javascript:void(0);" class="a-close" onclick="deleteListPic(this)"></a>' +
                                            '<img src="' + response.data[i].path + '" width="99%"  class="epic"/>' +
                                            '<input type="hidden" value="'+response.data[i].path+'" name="pic[]">'+
                                            '</div></span>');
                                }
                            }
                        }else{

                        }

                    }
                });
            });
        }
    })(jQuery);


    function savePhoto(){
        var data= $("#addManagerForm").serialize();
        $.post("<{U('saveEventPhoto')}>",data,function(re){
            if(re.status==0){
                details.remove();
            }
            layer.msg(re.msg);
        },'json');
    }

    //删除图片
    function deleteListPic(obj) {
        $(obj).parents('.picture_box').remove();
    }
</script>
